﻿#ifndef __DAHUA_GENICAM_ISTREAMSOURCE_H__
#define __DAHUA_GENICAM_ISTREAMSOURCE_H__

#include "Defs.h"
#include "Frame.h"
#include "Infra/Signal.h"

GENICAM_NAMESPACE_BEGIN

/// \~chinese
/// \brief 娴佸璞℃帴鍙ｇ被
/// \defgroup stream 娴佸璞℃搷浣沧帴鍙?
/// @{
/// \~english
/// \brief stream object interface class
/// \defgroup stream Stream Operation Interface
/// @{

/// \~chinese
/// \brief Class IStreamSource 娴佸璞℃帴鍙?
/// \~english
/// \brief Class IStreamSource stream object interface
class GENICAM_API IStreamSource
{
protected:
	/// \~chinese
	/// \brief 鏋愭瀯鍑芥暟
	/// \~english
	/// \brief destructor
	virtual ~IStreamSource(){}
	
public:	

	enum EGrabStrategy
	{
		grabStrartegySequential  = 0,	///< \~chinese 鎸夊埌杈鹃『搴忓鐞嗗浘鐗?///< \~english The images are processed in the order of their arrival
		grabStrartegyLatestImage = 1,   ///< \~chinese 銮峰彇链€鏂扮殑锲剧墖		///< \~english get the latest image
		grabStrartegyUndefined   		///< \~chinese 链畾涔?			///< \~english undefined
	};

	/// \~chinese	
	/// \brief 璁惧娴佸洖璋冨嚱鏁板０鏄?姣忔锲炶皟阃佸嚭涓€甯ф暟鎹?
	/// CFrame 锲炶皟镞朵富锷ㄦ帹阃佺殑甯у璞?
	/// \~english
	/// \brief Callback function declaration of stream: Send out one frame at each time use callback function
	/// CFrame The frame which will be active pushed out during the callback
	typedef Infra::TSignal1<const CFrame&> Signal;
	typedef Signal::Proc Proc;

    /// \~chinese	
    /// \brief 璁惧娴佸洖璋冨嚱鏁板０鏄?姣忔锲炶皟阃佸嚭涓€甯ф暟鎹拰鐢ㄦ埛鏁版嵁
    /// CFrame 锲炶皟镞朵富锷ㄦ帹阃佺殑甯у璞?
    /// void*  锲炶皟镞舵帹阃佺殑鐢ㄦ埛鏁版嵁
    /// \~english
    /// \brief Callback function declaration of stream: Send out one frame and user data at each time use callback function
    /// CFrame The frame which will be active pushed out during the callback
    /// void* The user data which will be active pushed out during the callback
    typedef Infra::TSignal2<const CFrame&, const void*> SignalEx;
    typedef SignalEx::Proc ProcEx;

	/// \~chinese
	/// \brief 寮€濮嬫姄锲?
	/// \param [in] maxImagesGrabbed 鍏佽链€澶氱殑鎶揿浘鏁帮紝杈惧埌鎸囧畾鎶揿浘鏁板悗锅沧鎶揿浘锛屽鏋滀负0锛岃〃绀哄拷鐣ユ鍙傛暟杩炵画鎶揿浘
	/// \param [in] strategy 鎶揿浘绛栫暐,榛樿鎸夌紦瀛橀槦鍒椾腑镄勯『搴忔姄锲?
	/// \return 杩斿洖鎶揿浘鏄惁鎴愬姛
	/// \~english
	/// \brief Start grabbing
	/// \param [in] maxImagesGrabbed Maximum images allowed to grab, once it reaches the limit then stop grabbing; If it is 0, then ignore this parameter and start grabbing continuously
	/// \param [in] strategy Image grabbing strategy; Image grabbing according to the order in buffer queue is default
	/// \return success:true, fail:false
	virtual bool startGrabbing(uint64_t maxImagesGrabbed = 0,EGrabStrategy strategy = grabStrartegySequential) = 0;
					
	/// \~chinese
	/// \brief 锅沧鎶揿浘
	/// \return 杩斿洖锅沧鎶揿浘鏄惁鎴愬姛
	/// \~english
	/// \brief Stop grabbing
	/// \return success:true, fail:false
	virtual bool stopGrabbing() = 0;
							
	/// \~chinese
	/// \brief 鏄惁姝ｅ湪鎶揿浘
	/// \return 杩斿洖鏄惁鎴愬姛
	/// \~english 
	/// \brief Check whether it is grabbing or not
	/// \return grabbing or not grabbing, true means it is grabbing, false means it is not grabbing
	virtual bool isGrabbing() = 0;
				
	/// \~chinese
	/// \brief 銮峰彇涓€甯у浘镀忥紝璇ユ帴鍙ｄ笉鏀寔澶氱嚎绋嬭皟鐢?
	/// \param [out] frame 涓€甯у浘镀?
	/// \param [in]  timeoutMS 銮峰彇涓€甯у浘镀忕殑瓒呮椂镞堕昵,鍗曚綅MS,褰揿€间负INFINITE镞惰〃绀烘棤闄愮瓑寰?
	/// \return 杩斿洖鏄惁鎴愬姛
	/// \~english
	/// \brief get a frame image, and this interface does not support multi-threading
	/// \param [out] frame one frame
	/// \param [in]  timeoutMS The timeout value of getting one image, unit is MS; When the value is INFINITE which means infinite wait
	/// \return success:true, fail:false
	virtual bool getFrame(CFrame &frame,uint32_t timeoutMS = INFINITE) const = 0;

	/// \~chinese
	/// \brief 娉ㄥ唽鏁版嵁甯у洖璋冨嚱鏁般€傝寮傛銮峰彇甯ф満鍒跺拰鍚屾銮峰彇甯ф満鍒朵簰鏂ワ紝绯荤粺涓袱钥呭彧鑳介€夊叾涓€銆?
	/// \param [in] proc 鏁版嵁甯у洖璋冨嚱鏁帮紝寤鸿涓嶈鍦ㄨ鍑芥暟涓鐞呜€楁椂镄勬搷浣滐紝鍚﹀垯浼氶樆濉炲悗缁暟鎹抚镄勫疄镞舵€?
	/// \return 杩斿洖娉ㄥ唽鏄惁鎴愬姛
	/// \~english
	/// \brief Register data frame callback function; This asynchronous frame acquisition mechanism and synchronous frame acquisition mechanism are mutually exclusive, only one method can be choosed between these two in system
	/// \brief only callback one function 
	/// \param [in] proc Data frame callback function; It is advised to not put time-cosuming operation in this function, otherwise it will block follow-up data frames and affect real time performance
	/// \return success:true, fail:false
	virtual bool attachGrabbing(Proc proc) = 0;

	/// \~chinese
	/// \brief 铡绘敞鍐屾暟鎹抚锲炶皟鍑芥暟
	/// \param [in] proc 铡绘敞鍐屾暟鎹抚锲炶皟鍑芥暟
	/// \return 杩斿洖铡绘敞鍐屾槸鍚︽垚锷?
	/// \~english
	/// \brief Unregister data frame callback function
	/// \param [in] proc Unregister data frame callback function
	/// \return success:true, fail:false
	virtual bool detachGrabbing(Proc proc) = 0;
	
	/// \~chinese
    /// \brief 璁剧疆缂揿瓨涓暟,涓嶈兘鍦ㄦ媺娴佽绷绋嬩腑璁剧疆
    /// \param [in]  nSize 缂揿瓨鏁伴噺锛屾渶澶т负200
    /// \return 杩斿洖鏄惁鎴愬姛
	/// \~english
	/// \brief Set buffer count, this cannot be set during frame grabbing
	/// \param [in]  nSize the buffer count锛?max size is 200.
	/// \return success:true, fail:false
    virtual bool setBufferCount(uint32_t nSize) = 0;

    /// \~chinese
    /// \brief 娉ㄥ唽鏁版嵁甯у洖璋冨嚱鏁?鍖呭惈鐢ㄦ埛镊畾涔夋暟鎹?銆?
    /// \param [in] proc 鏁版嵁甯у洖璋冨嚱鏁帮紝寤鸿涓嶈鍦ㄨ鍑芥暟涓鐞呜€楁椂镄勬搷浣滐紝鍚﹀垯浼氶樆濉炲悗缁暟鎹抚镄勫疄镞舵€?
    /// \param [in] pUser 鐢ㄦ埛镊畾涔夋暟鎹?
    /// \return 杩斿洖娉ㄥ唽鏄惁鎴愬姛
    /// \~english
    /// \brief Register data frame callback function(include user defined data); 
    /// \param [in] proc Data frame callback function; It is advised to not put time-cosuming operation in this function, otherwise it will block follow-up data frames and affect real time performance
    /// \param [in] pUser user defined data
    /// \return success:true, fail:false
    virtual bool attachGrabbingEx(ProcEx proc, void* pUser) = 0;

    /// \~chinese
    /// \brief 铡绘敞鍐屾暟鎹抚锲炶皟鍑芥暟(鍖呭惈鐢ㄦ埛镊畾涔夋暟鎹?
    /// \param [in] proc 铡绘敞鍐屾暟鎹抚锲炶皟鍑芥暟
    /// \param [in] pUser 鐢ㄦ埛镊畾涔夋暟鎹?涓巃ttachGrabbingEx镄刾User鐩稿悓)
    /// \return 杩斿洖铡绘敞鍐屾槸鍚︽垚锷?
    /// \~english
    /// \brief	Unregister data frame callback function(include user defined data)
    /// \param [in] proc Unregister data frame callback function(the same pUser of the attachGrabbingEx)
    /// \param [in] pUser user defined data
    /// \return success:true, fail:false
    virtual bool detachGrabbingEx(ProcEx proc, void* pUser) = 0;

    /// \~chinese
    /// \brief 璁剧疆椹卞姩鍖呴棿闅旀椂闂?ms),浠呭Gige璁惧链夋晥
    /// \param [in] nTimeout 鍖呴棿闅旀椂闂达紝鍗曚綅ms
    /// \return 璁剧疆鏄惁鎴愬姛,true琛ㄧず鎴愬姛锛宖alse琛ㄧず澶辫触
    /// \~english
    /// \brief	set packet timeout(ms), just for GigE devices
    /// \param [in] the value of timeout
    /// \return success:true, fail:false
    virtual bool setInterPacketTimeout(uint32_t nTimeout) = 0;
};

typedef Memory::TSharedPtr<IStreamSource> IStreamSourcePtr;
/// @}

GENICAM_NAMESPACE_END

#endif //__DAHUA_GENICAM_ISTREAMSOURCE_H__